package com.hzhc.controller.pad;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzhc.annotation.SysTemLog;
import com.hzhc.common.BaseController;
import com.hzhc.dto.UserDto;
import com.hzhc.enumBean.ResultUtilCodeEnum;
import com.hzhc.service.CntrInfoService;
import com.hzhc.service.TrainPlanDetailService;
import com.hzhc.service.TrainPlanService;
import com.hzhc.utils.ResultUtil;
import com.hzhc.utils.TokenUtil;
import com.hzhc.vo.CntrTallyVo;
import com.hzhc.vo.TrainPlanDetailVo;
import com.hzhc.vo.TrainPlanVo;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author dongcy
 * @date 2024/6/4 16:37
 * @description IpadCntrZcTallyController  ipad装车理货
 */
@RestController
@RequestMapping("/ipad")
@RequiredArgsConstructor
public class IpadCntrXcTallyController extends BaseController {

    private final TrainPlanDetailService detailService;
    private final CntrInfoService cntrInfoService;

    private final TrainPlanService trainPlanService;


    /**
     * 卸车理货(出场)  列表list
     * @param vo
     * @return
     */
    @RequestMapping("/getTrainPlanList")
    @ResponseBody
    public ResultUtil<List<TrainPlanVo>> getAllTrainPlanDetail(@RequestBody TrainPlanVo vo){
        Page<TrainPlanVo> page = new Page<>(vo.getPageIndex(),vo.getPageSize());
        List<TrainPlanVo> list = trainPlanService.getAppTrainPlanList(page,vo);
        return ResultUtil.build(list,page.getTotal(),page.getPages(), ResultUtilCodeEnum.SUCCESS);
    }

    /**
     * 卸车理货集装箱列表list
     * @param vo
     * @return
     */
    @RequestMapping("/getTrainPlanDetailList")
    @ResponseBody
    public ResultUtil<List<TrainPlanDetailVo>> getTrainPlanDetailList(@RequestBody TrainPlanDetailVo vo){
        Page<TrainPlanDetailVo> page = new Page<>(vo.getPageIndex(),vo.getPageSize());
        List<TrainPlanDetailVo> list = detailService.getXcTrainPlanDetail(page,vo);
        return ResultUtil.build(list,page.getTotal(),page.getPages(), ResultUtilCodeEnum.SUCCESS);
    }

    /**
     * ipad 卸车理货
     * @param vo
     * @return
     */
    @PostMapping("/cntrXcTallyIpad")
    @SysTemLog(operModul = "卸车理货", operType = "理货", operDesc = "卸车理货功能", modular = "IPAD")
    public ResultUtil<T> cntrXcTallyIpad(HttpServletRequest request, @RequestBody CntrTallyVo vo){
        UserDto user = TokenUtil.getUser(request);
        vo.setUserId(user.getId());
        vo.setUserName(user.getRealname());
        vo.setAccesspath("平板端");
        return cntrInfoService.cntrXcTally(vo);
    }

    //pad 卸车理货 add单个数据
    @RequestMapping("/cntrXcTallyByOne")
    public ResultUtil<T> addXcData(HttpServletRequest request,@RequestBody TrainPlanDetailVo detail){
        UserDto user = TokenUtil.getUser(request);
        detail.setUserId(user.getId());
        return detailService.addXcData(detail);
    }

}
